package com.xinfu.newproject.adapter.property_provider;

import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.xinfu.newproject.R;
import com.xinfu.newproject.adapter.preperty_adapter.PropertyAdapter;
import com.xinfu.newproject.bean.TestPropertyPayCostBean;
import com.xinfu.newproject.entity.NormalMultipleEntity;
import com.xinfu.newproject.interface_.PropertyInterface;

import java.util.ArrayList;
import java.util.List;

/**
 * https://github.com/chaychan
 *
 * @author ChayChan
 * @description: Img ItemProvider
 * @date 2018/3/30  11:39
 */

public class PropertyOneProvider extends BaseItemProvider<NormalMultipleEntity, BaseViewHolder> implements CompoundButton.OnCheckedChangeListener, PropertyInterface {

    private RecyclerView recyclerView;
    private PropertyAdapter propertyAdapter;
    private CheckBox checkBox;
    private List<TestPropertyPayCostBean> list;

    public void addBoolean(boolean allCheck) {
        if (checkBox != null) {
            checkBox.setChecked(allCheck);
            if (list != null && propertyAdapter != null) {
                Log.i("testOne", allCheck + "2222");
                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setClickble(allCheck);
                }
                Log.i("testOne", list.get(1).isClickble() + "list");
                List<Integer> typeList = new ArrayList<>();
                typeList.add(1);
                propertyAdapter.addbean(list);
            }
        }
    }

    @Override
    public int viewType() {
        return PropertyMultipleItemRvAdapter.TYPE_PROPERTY_ONE;
    }

    @Override
    public int layout() {
        return R.layout.item_property_one;
    }

    @Override
    public void convert(BaseViewHolder helper, NormalMultipleEntity data, int position) {
        recyclerView = helper.getView(R.id.item_property_one_rv);
        checkBox = helper.getView(R.id.item_property_one_all_cb);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        list = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            TestPropertyPayCostBean testPropertyPayCostBean = new TestPropertyPayCostBean();
            testPropertyPayCostBean.setPrice("¥ 30");
            testPropertyPayCostBean.setStringTime("2019年7月");
            list.add(testPropertyPayCostBean);
        }
        List<Integer> typeList = new ArrayList<>();
        typeList.add(1);

        propertyAdapter = new PropertyAdapter(mContext, list);
        recyclerView.setAdapter(propertyAdapter);
        checkBox.setOnCheckedChangeListener(this);


//        if (position % 2 == 0) {
//            helper.setImageResource(R.id.iv, R.mipmap.ic_launcher);
//        }else{
//            helper.setImageResource(R.id.iv, R.mipmap.ic_launcher);
//        }
    }


    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        Log.i("testOne", b + "3333");
        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                list.get(i).setClickble(b);
            }
            propertyAdapter.notifyDataSetChanged();
        }

    }

    @Override
    public void setPropertyCheckBox(boolean propertyCheckBox) {

    }
}
